<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="inc/connmysql.jsp"%>
<%@ include file="utils/function.jsp"%>

<%
//逻辑代码
String newname = toUTF(request.getParameter("newname"));
String newcode1 = toUTF(request.getParameter("newcode1"));
String newcode2 = toUTF(request.getParameter("newcode2")); //取出用户输入的注册信息

PreparedStatement psmt1 = conn.prepareStatement("Select username from users where username=?");
psmt1.setString(1,newname);
ResultSet rs = psmt1.executeQuery();
	
if ("".equals(newname)||"".equals(newcode1)||"".equals(newcode2)){
	response.sendRedirect("sign2.jsp"); //注册信息为空
	
}
else if (rs.next()){
	response.sendRedirect("sign1.jsp");  //用户名已存在
}
else if (newcode1.equals(newcode2)){
	PreparedStatement psmt2=conn.prepareStatement("INSERT INTO users VALUES(?,?)");
	psmt2.setString(1,newname);
	psmt2.setString(2,newcode1);
	psmt2.executeUpdate();
	response.sendRedirect("Login.jsp");    //添加成功
	
	
}
else {
	response.sendRedirect("sign3.jsp");  //确认密码不一致
}
%>
<%@ include file="inc/connmysql_close.jsp"%>
